//
//  HDBaseViewController.swift
//  HDSwfitWeibo
//
//  Created by wty on 16/4/8.
//  Copyright © 2016年 wty. All rights reserved.
//

import UIKit

class HDBaseViewController: UITableViewController {
     //用户是否登录
    var userLogin = HDUserAccoutViewModel.userAccoutShare.userLogin
    //加载控制器的view  如果是调用super.loadView , 就是加载登录界面的画面   如果改变了view  就显示view
    override func viewDidLoad() {
        userLogin ? super.viewDidLoad() : setupVisitorView()
    }
    private func setupVisitorView() {
        view  = visitorView
        visitorView.delegate = self
        view.backgroundColor = UIColor(colorLiteralRed: 237/255.0, green: 237/255.0, blue: 237/255.0, alpha: 1.0)

        switch self  {
        case is HDHomeController : visitorView.startAnimation()
        case is HDMessageController : visitorView.setupVisitor("visitordiscover_image_message", message: "登录后，别人评论你的微博，发给你的消息，都会在这里收到通知")
        case is HDDiscoverController: visitorView.setupVisitor("visitordiscover_image_message", message: "登录后，最新、最热微博尽在掌握，不再会与实事潮流擦肩而过")
        case is HDProfiltController : visitorView.setupVisitor("visitordiscover_image_profile", message: "登录后，你的微博、相册、个人资料会显示在这里，展示给别人")
        default :print("error")
        }
        //改变导航栏item颜色
        let barButtonItemAppearance = UIBarButtonItem.appearance()
        barButtonItemAppearance.tintColor = UIColor.orangeColor()
        //设置导航栏的按钮
        navigationItem.leftBarButtonItem = UIBarButtonItem(title: "注册", style: UIBarButtonItemStyle.Plain, target: self, action: Selector("visitorViewDidClickRegisterButton"))
        navigationItem.rightBarButtonItem = UIBarButtonItem(title: "登录", style: UIBarButtonItemStyle.Plain, target: self, action: Selector("visitorViewDidClickLoginButton"))

    }

    //MARK 懒加载
    private lazy var visitorView :HDVisitorView = HDVisitorView()
}
//遵守协议 实现代理方法  
extension  HDBaseViewController :HDVisitorViewDelegate {
    //实现导航栏的按钮监听
     func visitorViewDidClickRegisterButton () {
         print("xxxx")
    }
     func visitorViewDidClickLoginButton() {
        print("ooooo")
        //modal出登陆界面
        let  oauth = HDOauthViewController()
        let nav = UINavigationController(rootViewController: oauth)
        self.presentViewController(nav, animated: true, completion: nil)
    }
    
}
